<?php
/**
 * Created by PhpStorm.
 * User: ysfl
 * Date: 2015/11/24
 * Time: 16:44
 */

namespace modules\admin;

use Cross\MVC\Module;

class RegisterModule extends Module
{
    /**
     * 管理员表
     *
     * @var string
     */
    protected $t_admin = 'admin';

    /**
     * 新增加管理员
     *
     * @param $data
     * @return bool
     */
    function registerAdmin($data)
    {
        if (empty($data['user']) || empty($data['pwd']) || empty($data['pwd2']) || empty($data['name']) || empty($data['mobile'])) {
            return "信息没有填写完整！";
        }

        if ($this->link->get($this->t_admin, 'name', array('name' => $data['user']))){
            return "这个账号已经存在！";
        }



        foreach ($data as $k => & $d) {
            if (empty($d)) {
                unset($data[$k]);
                return "没有获取相关数据！";
            }

            if ($k == 'pwd') {
                $d = sha1(md5($data ['pwd']));
            }

            $sql = array(
                'name' => $data['user'],
                'password' => $d,
                'uname' => $data['name'],
                'mobile' => $data['mobile']
            );
        }

        if ($this->link->add($this->t_admin, $sql)){
            return "注册成功！";
        }
        else{
            return "操作失败，请联系管理员";
        }
    }
}